package com.nikmesoft.android.alwaysontime.activities;

import java.io.IOException;
import java.util.List;

import com.nikmesoft.android.alwaysontime.R;
import com.nikmesoft.android.alwaysontime.beans.Employee;
import com.nikmesoft.android.alwaysontime.xml.SAXXMLParser;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.Toast;

public class HomeActivity extends BaseActivity implements
OnClickListener, OnItemSelectedListener {

	Button button;
    Spinner spinner;
    List<Employee> employees = null;

 

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_home);
		findViewsById();
        button.setOnClickListener(this);
    }
 
	
	
	
    private void findViewsById() {
        button = (Button) findViewById(R.id.button);
        spinner = (Spinner) findViewById(R.id.spinner);
    }
 
    public void onClick(View v) {
        try {
            employees = SAXXMLParser.parse(getAssets().open("employees.xml"));
            ArrayAdapter<Employee> adapter = new ArrayAdapter<Employee>(this,
                    R.layout.list_item, employees);
            spinner.setAdapter(adapter);
            spinner.setOnItemSelectedListener(this);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int pos,
            long id) {
        Employee employee = (Employee) parent.getItemAtPosition(pos);
        Toast.makeText(parent.getContext(), employee.getDetails(),
                Toast.LENGTH_LONG).show();
    }
 
    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
    }



}
